#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <aclconio.h>
#include <define.h>
#include <transact.h>
#include <tran.h>
#include <gds.h>
#include <sizes.h>
#include "ConfProto.h"
#include "tblutil.h"
#include <\SOFTPAY\Ver30\source\include\sizes.h>
#include <\SOFTPAY\Ver30\HostSrc\citisrc\citiids.h>
#include <\SOFTPAY\Ver30\HostSrc\cpacsrc\cpacids.h>
#include <confio.h>

#include <\SOFTPAY\Ver30\source\include\ETT.h>



static void *storeFromStruct;

static int recordNum;
void registerETT(void *ptr)
{
	 storeFromStruct = ptr;
}

void *dealWithAddressBoundary(void*address);
int	inLoadETTRecFromStruct (int inRecNumber, void *vdStruct)
{
	int inRet;
	char* tmp = (char*)vdStruct;

	registerETT(vdStruct);
	vdStruct = dealWithAddressBoundary(vdStruct);
	inRet = inLoadConfRec(ETT_FILENAME, SIZE_ETT_REC, inRecNumber, vdStruct);

	recordNum = inRecNumber;
	return inRet;
}

void vdRestoreETTRecFromStruct(void *vdStruct)
{
	registerETT(vdStruct);
	vdStruct = dealWithAddressBoundary(vdStruct);
	memcpy((char *) pvdGetETTRec(), vdStruct, SIZE_ETT_REC);

}

void vdCopyETTRecFromStruct(void *vdStruct)
{
	registerETT(vdStruct);
	vdStruct = dealWithAddressBoundary(vdStruct);
		memcpy(vdStruct, (char *) pvdGetETTRec(), SIZE_ETT_REC);

}

int	inSaveETTRecFromStruct (int inRecNumber,  void *vdStruct)
{
	int inRet;

	registerETT(vdStruct);
	vdStruct = dealWithAddressBoundary(vdStruct);
	inRet = inSaveConfRec(ETT_FILENAME, SIZE_ETT_REC, inRecNumber, (char *) vdStruct);

	return inRet;
}

int	inUpdateETTRecFromStruct (void *vdStruct)
{
	int inRet;

	registerETT(vdStruct);
	vdStruct = dealWithAddressBoundary(vdStruct);
	inRet = inSaveConfRec(ETT_FILENAME, SIZE_ETT_REC, recordNum, (char *) vdStruct);

	return inRet;
}

short inGetTenureFromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return inGetTenure();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((ETT_REC*)vdStruct)->inTenure;
}

void vdSetTenureFromStruct(short inTenure, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetTenure(inTenure);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	((ETT_REC*)vdStruct)->inTenure = inTenure;
}

VS_BOOL fGetEnableFromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return fGetEnable();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((ETT_REC*)vdStruct)->fEnable;
}

void vdSetEnableFromStruct(VS_BOOL fEnable, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetEnable(fEnable);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	((ETT_REC*)vdStruct)->fEnable = fEnable;
}

